<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="searchInpt"
        placeholder="输入ID/昵称/手机号"
        clearable
        @keyup.enter.native="search()"
        class="search-btn"
      >
        <el-button
          type="primary"
          @click="search()"
          icon="el-icon-search"
          slot="append"
          :loading="searchLoading"
        >搜索</el-button>
      </el-input>

      <div class="lz-tips">
        <label>活动筛选:</label>
      </div>
      <el-select
        v-model="taskStatusValue"
        placeholder="活动筛选"
        @change="getAuditUpload()"
      >
        <el-option
          v-for="item in taskStatus"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <div class="table-container">
      <Table :table="dataTable">
        <template
          slot-scope="props"
          slot="imgUrl"
        >
          <el-button
            type="text"
            @click="showImgDialogBox(props.obj.row.imgUrl)"
            size="small"
          >查看图片</el-button>
        </template>
      </Table>
      <div
        class="Pagination"
        style="text-align: left;margin-top: 10px;"
      >
        <el-pagination
          v-if="pageshow"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="limit"
          layout="total, prev, pager, next"
          :total="count"
        >
        </el-pagination>
      </div>
    </div>

    <el-dialog
      title="存档内容"
      :visible.sync="showImgDialog"
      top="4%"
      width="40%"
    >
      <div class="demo-image__lazy">
        <div
          v-for="(pic,index) in picture"
          :key="index"
        >
          <vue-photo-zoom-pro :url="pic"></vue-photo-zoom-pro>
        </div>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import { fetchAuditList, fetchTaskList } from "@/api/table";
import format from "date-format";
import Table from "@/components/Table";
export default {
  data() {
    return {
      //总页码
      count: 0,
      //单页行数
      limit: 20,
      //页码
      currentPage: 1,
      searchInpt: "",
      searchLoading: false,
      //活动删选
      taskStatus: [
        {
          value: "",
          label: "全部活动"
        }
      ],
      taskStatusValue: "",
      dataTable: {
        loading: false,
        border: true,
        hasOperation: false,
        tr: [
          {
            id: "1",
            label: "ID",
            prop: "userId",
            show: true
          },
          {
            id: "2",
            label: "手机号",
            prop: "userName",
            show: true
          },
          {
            id: "3",
            label: "昵称",
            prop: "nickName",
            show: true
          },
          {
            id: "4",
            label: "任务名称",
            prop: "taskName",
            show: true
          },
          {
            id: "5",
            label: "上传时间",
            prop: "createTime",
            show: true
          },
          {
            id: "8",
            label: "审核时间",
            prop: "auditTime",
            show: true
          },
          {
            id: "9",
            label: "审核人员",
            prop: "reviewers",
            show: true
          },
          {
            id: "6",
            label: "上传内容",
            prop: "imgUrl",
            show: "template"
          },
          {
            id: "7",
            label: "审核结果",
            prop: "auditStatus",
            show: true
          },
          {
            id: "10",
            label: "失败原因",
            prop: "auditDescription",
            show: true
          }
        ],
        data: [],
        operation: {}
      },
      showImgDialog: false,
      picture: [],
      pageshow: true
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.getAuditUpload();
      this.getTaskLis();
    },
    //时间格式化
    formatterTime(t) {
      if (t) {
        const newTime = format("yyyy-MM-dd hh:mm:ss", new Date(t)).split(" ");
        let time = "";
        time += newTime[0] + "\n" + newTime[1];
        return time;
      } else {
        return "";
      }
    },
    showImgDialogBox(img) {
      if (img) {
        this.showImgDialog = true;
        this.picture = img.split(",");
      } else {
        this.$message({
          type: "error",
          message: "无图片"
        });
      }
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getAuditUpload();
    },
    search() {
      this.currentPage = 1;
      this.pageshow = false;
      this.getAuditUpload();
      this.$nextTick(() => {
        this.pageshow = true;
      });
    },
    async getTaskLis() {
      const res = await fetchTaskList();
      res.data.forEach(item => {
        const task = {};
        task.label = item.taskName;
        task.value = item.id;
        this.taskStatus.push(task);
      });
    },
    async getAuditUpload() {
      this.dataTable.loading = true;
      this.searchLoading = true;
      const res = await fetchAuditList({
        pageSize: this.limit,
        pageNo: this.currentPage,
        key: this.searchInpt,
        taskId: this.taskStatusValue
      });
      this.searchLoading = false;
      this.dataTable.loading = false;
      this.dataTable.data = [];
      this.count = res.data.total;
      res.data.list.forEach(item => {
        const data = {};
        data.userId = item.userId;
        data.taskRecordId = item.taskRecordId;
        data.nickName = item.nickName;
        data.userName = item.userName;
        data.orderNum = item.orderNum;
        data.reviewers = item.reviewers;
        data.taskName = item.taskName;
        data.createTime = this.formatterTime(item.createTime);
        data.auditTime = this.formatterTime(item.auditTime);
        data.imgUrl = item.imgUrl;
        data.reward = item.reward;
        data.auditDescription = item.auditDescription;
        if (item.auditStatus == "0") {
          data.auditStatus = "审核中";
        } else if (item.auditStatus == "5") {
          data.auditStatus = "审核未通过";
        } else if (item.auditStatus == "10") {
          data.auditStatus = "已审核";
        }
        this.dataTable.data.push(data);
      });
    }
  },
  components: {
    Table
  }
};
</script>
